/*
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-05-12 15:44:23
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-05-13 21:44:47
 * @FilePath: \cesium_visualBasic\src\1.白膜加载.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as Cesium from 'cesium'
import *as dat from 'dat.gui'
import { update3dtilesMaxtrix } from './utils';
import{TencentImageryProvider} from'./utils/mapPlugin'
Cesium.Ion.defaultAccessToken = window.config.token;
const gui  = new dat.GUI();
const viewer = new Cesium.Viewer('cesiumContainer');
//添加地图
// const tencentImageryProvider = new Cesium.UrlTemplateImageryProvider({
//     url:"https://p2.map.gtimg.com/sateTiles/{z}/{sx}/{sy}/{x}_{reverseY}.jpg?version=400",
//     customTags:{
//         sx:function(imageryProvider,x,y,level){
//             return x>>4
//         },
//         sy:function(imageryProvider,x,y,level){
//             return ((1<<level) - y)>>4
//         }
//     }
// })
//使用cesium-map中provider来进行加载
const tencentImageryProvider = new TencentImageryProvider({
    style:"4",
    crs:"WGS84"
})
viewer.imageryLayers.addImageryProvider(tencentImageryProvider)
//添加白膜
const tile = new Cesium.Cesium3DTileset({
    url: "http://localhost:8080/wuhan/tileset.json"
});

const tileset = viewer.scene.primitives.add(tile);
// console.log(tileset)
tileset.readyPromise.then(() => {
    // console.log(tileset.properties)   
    //给模型着色.通过3DtilleStyle语法
    tileset.style = new Cesium.Cesium3DTileStyle({
        color: {
            conditions: [
                // ['Number(${Elevation})<50', "color('rgb(97, 236, 16)',0.0)"],
                // ['Number(${Elevation})>50', "color('rgb(222, 231, 236)',1)"],
                // ['true', 'color("blue", 0.8)'] // 修正了颜色拼写错误，并统一了透明度
                ['${Elevation}<20', "color('rgb(97, 236, 16)',1)"],
                ['${Elevation}>20', "color('rgb(222, 231, 236)',1)"],
                ['true', 'color("blue", 0.8)'] // 修正了颜色拼写错误，并统一了透明度

            ]
        }
    });
    // update3dtilesMaxtrix()
    //更新3Dtiles包围盒
    const boundingShpere = tileset.boundingSphere;
    
    viewer.camera.flyToBoundingSphere(boundingShpere);
    const offset={
        tx:0,
        ty:0,
    }
    
    gui.add(offset,'tx',-1000,1000,1).onChange(
       ()=>{
        update3dtilesMaxtrix(offset.tx,offset.ty,tileset)
       }
    )
    gui.add(offset,'ty',-1000,1000,1).onChange(()=>{
        update3dtilesMaxtrix(offset.tx,offset.ty,tileset)
    })
});


